storBattery = new Vue({
	el: "#storBattery",
	data: {
		currentUser:'', // 当前用户信息
		parentObject:{},
		fileIds:'',
		fileList:[],
		safeCheck:{
			safetyFacilityCheckId: '', //安全设施检查记录主键
			workId: '', //工作主键
			workDesc: '', //工作描述
			checkTime: '', //检查时间
			checkStaffCode: '', //检查人编号
			checkStaffName: '', //检查人姓名
			checkArea: '', //检查区域
			remark: '', //备注
			client: '', //客户ID
			dataSource: 'NEIOS_APP'+localStorage.getItem("currVersion"), //数据来源
			status: '', //业务状态
			dataStatus: '', //是否有效参见码表0删除&1正常
			createBy: '', //创建人员
			createStaffName: '', //创建人姓名
			create: '', //创建时间
			modifyBy: '', //修改人员
			modifyStaffName: '', //修改人员姓名
			modify: '', //修改时间
			reserveField1: '', //扩展字段1
			reserveField2: '', //扩展字段2
			reserveField3: '', //扩展字段3
			reserveField4: '', //扩展字段4
			reserveField5: '', //扩展字段5
			checkItems: [], //检查项
		},
		checkPersonList:[],
		checkResultTypeList:[],
		checkPerson:'',
		isApprove: false,
		disabled: false,
		showAdd: false,
	},
	components:{
		processlog, // 流程日志	
	},
	created: function() {
		let _this = this
		_this.currentUser = JSON.parse(localStorage.getItem("neiosUser"))
		_this.parentObject = JSON.parse(localStorage.getItem("neiosGoDetail")).obj
		_this.safeCheck.checkTime = this.getTime(new Date(), 'day');
		let dictCodes = 'YES_OR_NO';
		let dict = mui.neiosCommon.queryDict(dictCodes, (data) => {
			if (data != '') {
				this.checkResultTypeList = data.YES_OR_NO;
				console.log(JSON.stringify(this.checkResultTypeList))
			}
		})
		
		_this.getCheckItems();
	},
	methods: {
		//获取时间
		getTime(myDate, type) {
			var realYear = myDate.getFullYear();
			var myMonth = myDate.getMonth() + 1;
			var realMonth = myMonth;
			var myDay = myDate.getDate();
			var realDay = myDay;
			var myHour = myDate.getHours();
			var realHours = myHour;
			var myMinute = myDate.getMinutes();
			var realMinute = myMinute;
			var mySecond = myDate.getSeconds();
			var realSecond = mySecond;
			if (myMonth < 10) {
				realMonth = "0" + myMonth;
			}
			if (myDay < 10) {
				realDay = "0" + myDay;
			}
			if (myMinute < 10) {
				realMinute = "0" + myMinute;
			}
			if (myHour < 10) {
				realHours = "0" + myHour;
			}
			if (mySecond < 10) {
				realSecond = "0" + mySecond;
			}
			var realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute + ':' +
				realSecond;
			if (type == "sec") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute + ':' + realSecond;
			} else if (type == "min") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute;
			} else if (type == "hour") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours;
			} else if (type == "day") {
				realDate = realYear + '-' + realMonth + '-' + realDay;
			} else if (type == "month") {
				realDate = realYear + '-' + realMonth;
			} else if (type == "year") {
				realDate = realYear;
			}
			return realDate;
		},
		//获取检查人
		getCheckPerson(workId) {
			let _this = this;
			let params = {
				workId: this.parentObject.workId
			};
			mui.neiosRequst.httpRequst('/app/regularWork/safeDevice/getCheckPerson', params,
				(data) => {
					console.log("参数："+JSON.stringify(data))
					if (data.code == '0') {
						_this.checkPersonList = data.data;
						for (let i = 0; i < _this.checkPersonList.length - 1; i++) {
							for (let j = i + 1; j < _this.checkPersonList.length; j++) {
								if (_this.checkPersonList[i].nodeDealStaffCode == _this.checkPersonList[j].nodeDealStaffCode) {
									_this.checkPersonList.splice(j, 1);
								}
							}
						}
						_this.checkPersonList.map(v => {
							_this.safeCheck.checkStaffCode = `${_this.safeCheck.checkStaffCode},${v.nodeDealStaffCode}`;
							_this.safeCheck.checkStaffName = `${_this.safeCheck.checkStaffName},${v.nodeDealStaffName}`;
							_this.checkPerson = `${_this.checkPerson},[${v.nodeDealStaffCode}]${v.nodeDealStaffName}`;
						})
						_this.safeCheck.checkStaffCode = _this.safeCheck.checkStaffCode.substring(1);
						_this.safeCheck.checkStaffName = _this.safeCheck.checkStaffName.substring(1);
						_this.checkPerson = _this.checkPerson.substring(1);
					}
				},
				(data) => {
					mui.toast("获取数据错误：" + data.msg);
				}
			);
		},
		//获取检查项列表
		getCheckItems(workId) {
			let _this = this;
			let params = {
				"workId": this.parentObject.workId
			}
		
			mui.neiosRequst.httpRequst('/app/regularWork/safeDevice/getCheckItems', params,
				(data) => {
					console.log("LLLLLL:"+JSON.stringify(data))
					if (data.code == '0') {
						_this.safeCheck = data.data.data;
						_this.safeCheck.checkArea = data.data.data.safetyFacilityCheck.checkArea;
						_this.fileIds = data.data.data.attachIds;
						_this.queryFiles(_this.fileIds)
					}
				},
				(data) => {
					mui.toast("获取数据错误：" + data.msg);
				}
			);
		},
		// 获取附件
		queryFiles (fileIds) {
			let _this = this
			let fileParams = {
				fileIds:fileIds
			}
			mui.neiosRequst.httpRequst('/app/common/getFileList', fileParams,
				function(data) {
					if (data.code == '0') {
						if (data.data != '' && data.data != null && data.data != undefined) {
							_this.fileList = data.data
						} else {
							_this.fileList = []
						}
					} else {
						mui.toast('获取附件失败，请稍后重试！')
					}
				},
				function() {
					mui.toast('获取附件失败，请稍后重试！')
				}
			);
		},
		// 下载
		downloadFile(item){
			let url = "/app/common/downloadFile";
			let param = {};
			param.fileId = item.fileId;
			mui.neiosCommon.downLoadFile(param,function(ret){
				mui.plusReady(function () {
					plus.nativeUI.closeWaiting();
				})
				var callbackID = plus.bridge.callbackId(function(ret){
					mui.toast(ret[0])
				}, function(err){
					mui.toast('文件下载失败')
				});
				alert(item.fileName)
				plus.bridge.execSync( "FileHelper", "doFileSave", [callbackID, ret, item.fileName, "Argus3", "Argus4"] )
			},function(err){
				mui.plusReady(function () {
					plus.nativeUI.closeWaiting();
				})
				mui.toast('文件下载失败')
			});
		},
		// 返回
		goBack () {
			mui.back()
		}
	}
});